package com.usian.provider;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.MessageProperties;
import com.usian.util.ConnectionUtil;

public class Send {
    private final static String EXCHANGE_NAME = "topic_exchange_test";

    public static void main(String[] argv) throws Exception {
        // 获取到连接
        Connection connection = ConnectionUtil.getConnection();
        // 获取通道
        Channel channel = connection.createChannel();
        // 声明exchange，指定类型为topic
        channel.exchangeDeclare(EXCHANGE_NAME, "topic",false);
        // 消息内容
        String messageAdd = "topic商品新增了， id = 1001";
        String messageEdit = "topic商品修改了， id = 1001";
        String messageDelete = "topic商品删除了， id = 1001";
        String messageFind = "topic商品查询， id = 1001";
        // 发送消息，并且指定routing key 为：insert ,代表新增商品
        channel.basicPublish(EXCHANGE_NAME, "item.insert",null, messageAdd.getBytes());
        channel.basicPublish(EXCHANGE_NAME, "item.update",null, messageEdit.getBytes());
        channel.basicPublish(EXCHANGE_NAME, "item.delete",null, messageDelete.getBytes());
        channel.basicPublish(EXCHANGE_NAME, "item.find",null,   messageFind.getBytes());
        System.out.println(" [topic商品服务：] Sent '" + messageAdd + "'");
        System.out.println(" [topic商品服务：] Sent '" + messageEdit + "'");
        System.out.println(" [topic商品服务：] Sent '" + messageDelete + "'");
        System.out.println(" [topic商品服务：] Sent '" + messageFind + "'");

        channel.close();
        connection.close();
    }
}